import 'package:flutter/material.dart';
import 'package:test1/tarbar/ContactsFrame.dart';
import 'package:test1/tarbar/MainFrame.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:test1/tarbar/MineFrame.dart';
import 'package:test1/tarbar/discoverFrame.dart';

class MainTabBar extends StatefulWidget {
  const MainTabBar({Key? key}) : super(key: key);

  @override
  State<MainTabBar> createState() => _MainTabBarState();
}

class _MainTabBarState extends State<MainTabBar> {
  int _selectedIndex = 0;

  List<Widget> _widgetOptions = [

  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _selectedIndex,
        children: [
          MainFramePage(),
          ContactsFrame(),
          DiscoverFrame(),
          MainFrame(),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        showSelectedLabels: true,
        showUnselectedLabels: true,
        selectedFontSize: 12,
        unselectedFontSize: 12,
        selectedItemColor: Colors.green,
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Image.asset(
              'asset/tabbar/tabbar_mainframe@3x.png',
              width: 20,
              height: 20,
            ),
            activeIcon: Image.asset(
              'asset/tabbar/tabbar_mainframeHL@3x.png',
              width: 20,
              height: 20,
            ),
            label: '微信',
          ),
          BottomNavigationBarItem(
            icon: Image.asset(
              'asset/tabbar/tabbar_contacts@3x.png',
              width: 20,
              height: 20,
            ),
            activeIcon: Image.asset(
              'asset/tabbar/tabbar_contactsHL@3x.png',
              width: 20,
              height: 20,
            ),
            label: '通讯录',
          ),
          BottomNavigationBarItem(
            icon: Image.asset(
              'asset/tabbar/tabbar_discover@3x.png',
              width: 20,
              height: 20,
            ),
            activeIcon: Image.asset(
              'asset/tabbar/tabbar_discoverHL@3x.png',
              width: 20,
              height: 20,
            ),
            label: '发现',
          ),
          BottomNavigationBarItem(
            icon: Image.asset(
              'asset/tabbar/tabbar_me@3x.png',
              width: 20,
              height: 20,
            ),
            activeIcon: Image.asset(
              'asset/tabbar/tabbar_meHL@3x.png',
              width: 20,
              height: 20,
            ),
            label: '我',
          ),
        ],
        currentIndex: _selectedIndex,
        onTap: _onItemTapped,
      ),
    );
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }
}
